package myJs.user

import scalatags.Text.all
import scalatags.Text.all._

import scala.scalajs.js
import scala.scalajs.js.Date
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}

/**
 * Created by yz on 2/3/2020
 */
@JSExportTopLevel("Genome")
object Genome {

  @JSExport("stateFmt")
  def stateFmt: js.Function = {
    (v: js.Any, row: js.Dictionary[js.Any]) =>
      val state1 = if (List("success").contains(row("state"))) {
        span(cls := "label label-success", "成功！")
      } else if (List("running").contains(row("state"))) {
        span("正在运行 ",
          img(cls := "runningImage", src := "/p3bacter/assets/images/running2.gif", width := 30, height := 20))
      } else if (List("wait", "preparing").contains(row("state"))) {
        span(
          span(cls := "label label-default", "排队中 "),
          all.raw("&nbsp;"),
          img(cls := "runningImage", src := "/p3bacter/assets/images/running2.gif", width := 30, height := 20))
      } else {
        span(cls := "label label-danger", "错误！")
      }
      state1.toString()
  }

  def getCurrentTime = {
    val myDate = new Date()
    val year = myDate.getFullYear()
    val month = myDate.getMonth() + 1
    val date = myDate.getDate()
    val h = myDate.getHours()
    val m = myDate.getMinutes()
    val s = myDate.getSeconds()
    s"${year}_${getNow(month)}_${getNow(date)}_${getNow(h)}_${getNow(m)}_${getNow(s)}"
  }

  def getNow(s: Int) = {
    if (s < 10) s"0${s}" else s"${s}"
  }



}
